package com.common.domain;

import lombok.Data;

import java.text.MessageFormat;

@Data
public class R<T> {
    //序列化ID，目的是为了向后兼容
    private static final long serialVersionUID = 1L;
    private T type;
    //响应码，返回状态
    private int code;
    //返回消息
    private String msg;
    //返回数据
    private T data;
    private Boolean status;
    private Long count;

    public static R ok(){
        R r = new R();
        r.setCode(200);
        r.setStatus(true);
        r.setMsg("success");
        return r;
    }
    public static R error(){
        R r = new R();
        r.setCode(500);
        r.setStatus(false);
        r.setMsg("失败");
        return r;
    }
    public R count(long count){
        this.setCount(count);
        return this;
    }
    public R data(T data){
        this.setData(data);
        return this;
    }
    public void setStatus(Boolean status){
      this.status=status;
    }
    public R msg(String message){
        this.setMsg(message);
        return this;
    }
    public Object getData(){
        return data;
    }
    public R msg(String message, Object... objects){
        this.setMsg(MessageFormat.format(message, objects));
        return this;
    }
}
